/**
 * Created on May 13, 2007
 */
package jvs.vfs.io;

import java.io.IOException;
import java.io.InputStream;

/**
 * Unix /dev/zero 
 * 
 * @author qiangli
 *
 */
public class ZeroInputStream extends InputStream {
	/**
	 * 
	 */
	public ZeroInputStream() {
	}

	/* (non-Javadoc)
	 * @see java.io.InputStream#read()
	 */
	public int read() throws IOException {
		return 0;
	}
	
	public int available() throws IOException {
		return Integer.MAX_VALUE;
	}

	public void close() throws IOException {
	}

	public synchronized void mark(int readlimit) {
	}

	public boolean markSupported() {
		return true;
	}

	public int read(byte[] b, int off, int len) throws IOException {
		if (b == null) throw new NullPointerException();
		if (off < 0 || len < 0 || off+len > b.length) throw new IndexOutOfBoundsException();
		if (len == 0) return 0;
		for (int i=off; i<off+len; i++) {
			b[i] = 0;
		}
		return len;
	}

	public int read(byte[] b) throws IOException {
		if (b == null) throw new NullPointerException();
		if (b.length == 0) return 0;
		for (int i=0; i<b.length; i++) {
			b[i] = 0;
		}
		return b.length;
	}

	public synchronized void reset() throws IOException {
	}

	public long skip(long n) throws IOException {
		return n;
	}
	
}
